use "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Chapter 4 Campaigns\Data\Second round.dta", clear

sort var2 
drop if _n>4
gsort -n
replace n=n/2

gen upper=pointestimate+1.9645*se
gen lower=pointestimate-1.9645*se
gen upper01=pointestimate_01+1.9645*se_01
gen lower01=pointestimate_01-1.9645*se_01
gen upper02=pointestimate_02+1.9645*se_02
gen lower02=pointestimate_02-1.9645*se_02

gen label=-.71

*Figure 4.7
twoway (scatter  n pointestimate , mcolor(black))  (rcap upper lower n, color(black) horizontal ) ///
(scatter  n pointestimate_01, mcolor(black) msymbol(S)) (rcap upper01 lower01 n, color(black) horizontal )  ///
(scatter  n pointestimate_02, mcolor(black) msymbol(T)) (rcap upper02 lower02 n, color(black) horizontal ), ///
xtitle("{bf:Model-Predicted Change in Probability}" "(upon changing alter from 1st r'nd incumbent voter to 1st r'nd opposition voter)") ///
graphregion(color(white)) plotregion(lstyle(yxline) lcolor(black)) ytitle("{bf:Sample: Ego voted in 1st Round for...}") ///
legend(off) title("{bf: Dependent Variable: Ego Runoff Vote Choice}", size(medsmall) color(black)) ///
xline(0, lcolor(black)) yscale(range(.75 4.25))  xscale(range(-.1 .8)) ///
ylab(4 "Garotinho" 3 "Ciro" 2 "HH" 1 "Marina", labsize(medsmall) labgap(3)) ///
ymlab(4 "(2002)" 3 "(2002)" 2 "(2006)" 1 "(2014)", labsize(small)) ///
text(3.85 .263 "(change in probability of voting for Lula in runoff)", size(small)) text(2.85 .279 "(change in probability of voting for Lula in runoff)", size(small)) ///
text(1.85 .387 "(change in probability of voting for Alckmin in runoff)", size(small) color(black)) text(.85 .367 "(change in probability of voting for Aécio in runoff)", size(small) color(black)) ///
text(3.5 -.07 "{it:N}=841", size(small))  ///
text(2 -.07 "{it:N}=392", size(small) color(black)) text(1 -.07 "{it:N}=120", size(small) color(black)) ///
yline(1.5 2.5, lcolor(black))

graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Chapter 4 Campaigns\Figures\round two CIs.tif", as(tif) replace
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR4_7.tif", as(tif) replace width(1500)
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR4_7.pdf", as(pdf) replace 
